package org.anderground.editor.gui.toolbar;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;

import org.anderground.editor.gui.MainWindow;
import org.anderground.editor.gui.view.State;
import org.anderground.editor.gui.view.standard.ViewTriggers;

public class StateToolBar extends JToolBar {
	public StateToolBar(MainWindow parent) {
		JToggleButton button; 
		
		ButtonGroup stateGroup = new ButtonGroup();
				
		button=new MoveLabelButton(parent);
		add(button);
		stateGroup.add(button);
		
		button=new MoveStationButton(parent);
		add(button);
		stateGroup.add(button);
		
		button=new AddTransferButton(parent);
		add(button);
		stateGroup.add(button);
		
		button=new AddTunnelButton(parent);
		add(button);
		stateGroup.add(button);
		
		button=new ScrollButton(parent);
		add(button);
		stateGroup.add(button);
		
		button=new SelectionButton(parent);
		add(button);
		button.setSelected(true);
		stateGroup.add(button);
		
		
	}
	
	class MoveStationButton extends JToggleButton {
		MoveStationButton(final MainWindow parent) {
			super("Move station");
			setFocusable(false);
			addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					ViewTriggers.state = State.STATIONS_MOVE;
					
				}
				
			});

			
		}
	}
	
	class SelectionButton extends JToggleButton {
		SelectionButton(final MainWindow parent) {
			super("Select station");
			setFocusable(false);
			addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					ViewTriggers.state = State.SELECTION;
					
				}
				
			});

			
		}
	}
	
	class MoveLabelButton extends JToggleButton {
		MoveLabelButton(final MainWindow parent) {
			super("Move label");
			setFocusable(false);
			addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					ViewTriggers.state = State.MOVE_LABEL;
				}
				
			});

			
		}
	}
	
	class ScrollButton extends JToggleButton {
		ScrollButton(final MainWindow parent) {
			super("Scroll");
			setFocusable(false);			
			addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					ViewTriggers.state = State.SCROLL;
				}
				
			});

			
		}
	}
	
	class AddTransferButton extends JToggleButton {
		AddTransferButton(final MainWindow parent) {
			super("Add transfer");
			setFocusable(false);
			addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					ViewTriggers.state = State.ADD_TRANSFER;
				}
				
			});

			
		}
	}
	
	class AddTunnelButton extends JToggleButton {
		AddTunnelButton(final MainWindow parent) {
			super("Add tunnel");
			setFocusable(false);
			addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					ViewTriggers.state = State.ADD_TRANSITION;
				}
				
			});

			
		}
	}
}
